using UnityEngine;
using System.IO;
using System.Text;
using System.Collections;

public class TestGUI : MonoBehaviour {

	public GUISkin guiSkin;
	//float nativeVerticalResolution = 1024.0f;

	/* ScrollView example */

	// Vector2 scrollViewVector = Vector2.zero;
	Vector2 scrollPosition0 = Vector2.zero;
	Vector2 scrollPosition1 = Vector2.zero;
	Vector2 scrollPosition2 = Vector2.zero;
	Vector2 scrollPosition3 = Vector2.zero;
	Vector2 scrollPosition4 = Vector2.zero;
	Vector2 scrollPosition5 = Vector2.zero;
	Vector2 scrollPosition6 = Vector2.zero;
	// string innerText = "I am inside the ScrollView";


	/* Using multiple Groups to clip the displayed Contents */

	public Texture2D bgImage; // background image that is 256 x 32
	public Texture2D fgImage; // foreground image that is 256 x 32
	public float playerEnergy = 1.0f; // a float between 0.0 and 1.0

	Rect rectWin = new Rect(10, 10, 360, 540);



	// Use this for initialization
	void Start () {
		Debug.Log(Screen.height);
		Debug.Log(Screen.width);
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void WinTechContent(int windowID)
	{
		scrollPosition0 = GUILayout.BeginScrollView(scrollPosition0, GUILayout.Width(360), GUILayout.Height(540));
		GUILayout.BeginVertical(GUI.skin.GetStyle("box"));

		GUILayout.Box("General");

		scrollPosition1 = GUILayout.BeginScrollView(scrollPosition1, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 10; i++)
		{
			GUILayout.Button("I am completely inside a first Area");
		}
		GUILayout.EndScrollView();

		GUILayout.Box("Military");

		scrollPosition2 = GUILayout.BeginScrollView(scrollPosition2, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 20; i++)
		{
			GUILayout.Button("I am inside a second Area");
		}
		GUILayout.EndScrollView();

		GUILayout.Box("Planetary");

		scrollPosition3 = GUILayout.BeginScrollView(scrollPosition3, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 15; i++)
		{
			GUILayout.Button("I am inside a third Area");
		}
		GUILayout.EndScrollView();

		GUILayout.Box("Cosmology");

		scrollPosition4 = GUILayout.BeginScrollView(scrollPosition4, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 12; i++)
		{
			GUILayout.Button("I am inside a forth Area");
		}
		GUILayout.EndScrollView();

		GUILayout.Box("Ecology");

		scrollPosition5 = GUILayout.BeginScrollView(scrollPosition5, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 16; i++)
		{
			GUILayout.Button("I am inside a fifth Area");
		}
		GUILayout.EndScrollView();

		GUILayout.Box("Sociology");

		scrollPosition6 = GUILayout.BeginScrollView(scrollPosition6, GUILayout.Width(340), GUILayout.Height(120));
		for (int i = 0; i < 10; i++)
		{
			GUILayout.Button("I am inside a sixth Area");
		}
		GUILayout.EndScrollView();



		GUILayout.EndVertical();
		GUILayout.EndScrollView();

		GUI.DragWindow();
	}

	void OnGUI()
	{
		if (guiSkin)
			GUI.skin = guiSkin;

		// The next line makes sure it rescales nicely to other resolutions.
		// GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1));

		//GUI.Button (new Rect(0,0,100,25), "Top-left");
		//GUI.Button (new Rect(Screen.width - 100,0,100,25), "Top-right");
		//GUI.Button (new Rect(0,Screen.height - 25,100,25), "Bottom-left");
		//GUI.Button (new Rect(Screen.width - 100,Screen.height - 25,100,25), "Bottom-right");

		rectWin = GUILayout.Window(0, rectWin, WinTechContent, "Technology List");


		//// Begin the ScrollView
		//scrollViewVector = GUI.BeginScrollView(new Rect(Screen.width - 400, 10, 400, 200), scrollViewVector, new Rect(Screen.width - 400, 0, 400, 800));

		//// Put something inside the ScrollView
		//// innerText = GUI.TextArea(new Rect(Screen.width - 400, 0, 400, 800), innerText);

		//string txt = (string)"I am completely inside an Area";
		//int length = txt.Length * 7;

		//GUILayout.BeginArea(new Rect(Screen.width - 400, 0, 400, 800));
		//GUILayout.Label("General");
		//GUILayout.Button("I am completely inside an Area", GUILayout.Height(20));
		//GUILayout.Button(txt, GUILayout.Width(length));
		//GUILayout.EndArea();


		//// End the ScrollView
		//GUI.EndScrollView();


		//// Fixed Layout
		//GUI.Button(new Rect(25, 25, 100, 30), "I am a Fixed Layout Button");

		//// Automatic Layout
		//GUILayout.Button("I am an Automatic Layout Button");


		//// Create one Group to contain both images
		//// Adjust the first 2 coordinates to place it somewhere else on-screen
		//GUI.BeginGroup( new Rect(0, 0, 256, 32));

		//// Draw the background image
		//GUI.Box(new Rect(0, 0, 256, 32), bgImage);

		//// Create a second Group which will be clipped
		//// We want to clip the image and not scale it, which is why we need the second Group
		//GUI.BeginGroup(new Rect(0, 0, playerEnergy * 256, 32));

		//// Draw the foreground image
		//GUI.Box(new Rect(0, 0, 256, 32), fgImage);

		//// End both Groups
		//GUI.EndGroup();
		//GUI.EndGroup();









	}
}

